package com.leetcode.algorithm.y22.m06;

/**
 * 1768. 交替合并字符串
 * 
 * https://leetcode.cn/problems/merge-strings-alternately/
 * 
 * @author jie.deng
 *
 */
class Question1768Solution01 {

	public String mergeAlternately(String word1, String word2) {
		int len1 = word1.length();
		int len2 = word2.length();
		StringBuilder builder = new StringBuilder(len1 + len2);
		for (int i = 0; i < Math.min(len1, len2); i++) {
			builder.append(word1.charAt(i));
			builder.append(word2.charAt(i));
		}
		if (len1 > len2) {
			builder.append(word1.substring(len2));
		} else {
			builder.append(word2.substring(len1));
		}
		return builder.toString();
	}

}